<%--
  Created by IntelliJ IDEA.
  User: 霞
  Date: 2024/9/25
  Time: 10:49
  To change this template use File | Settings | File Templates.
--%>
<%@ page contentType="text/html;charset=UTF-8" language="java" %>
<%@page import="java.sql.*" %>
<% request.setCharacterEncoding("UTF-8"); %>
<% String id = request.getParameter("stuid"); %>
<% String stuBirthday = request.getParameter("stubirthday"); %>
<% String stuClass = request.getParameter("stuclass"); %>
<head>
    <title>修改结果</title>
    <%! ResultSet rs;// 数据库查询结果 %>
    <%
        String dbName = "school";//数据库
        String userName = "root";//账户
        String userPassword = "hqx050607";//密码
        String url = "jdbc:mysql://localhost/" + dbName + "?user=" + userName + "&password=" + userPassword;
        Class.forName("com.mysql.cj.jdbc.Driver");//5.7以下不加.cj
        Connection conn = DriverManager.getConnection(url);//连接数据库
        String sql = "update student set birthday=?,stuclass=?where number=?";
        PreparedStatement preparedStatement =  conn.prepareStatement(sql);
        preparedStatement.setString(1,stuBirthday);
        preparedStatement.setString(2,stuClass);
        preparedStatement.setString(3,id);
        int result=preparedStatement.executeUpdate();
        if (result > 0)
            out.print(" <script type='text/javascript'>alert('修改成功');</script> ");
         else
            out.print(" <script type='text/javascript'>alert('修改失败');</script> ");
         sql = "select * from student";
         rs = preparedStatement.executeQuery(sql);

    %>
</head>
<html>
<head>
<body>
<table bgcolor="1">
    <th colspan="4" style="font-size: x-large;alignment: center">学生信息表</th>
    <tr style="text-align: center">
        <td>学号</td>
        <td>姓名</td>
        <td>出生日期</td>
        <td>所在班级</td>
    </tr>
    <%--  循环展示数据  --%>
    <%
        while (rs.next()){
    %>
    <tr style="text-align: center">
        <td><%=rs.getString(1)%></td>
        <td><%=rs.getString(2)%></td>
        <td><%=rs.getString(stuBirthday)%></td>
        <td><%=rs.getString(stuClass)%></td>
    </tr>
        <% } %>
<%
    rs.close();
    preparedStatement.close();
    conn.close();
%>

</table>
</body>
</html>
